package me.goldze.mvvmhabit.binding.viewadapter.autocompeteTextview;

import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import androidx.databinding.BindingAdapter;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseApplication;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class ViewAdapter {
    @BindingAdapter(value = {"autoCompetedata","onItemClickCommand"}, requireAll = false)
    public static void setAutoCompeteViewData(AutoCompleteTextView autoCompeteView, List<String> data, final BindingCommand<String> bindingCommand) {
        autoCompeteView.setAdapter(new ArrayAdapter<>(BaseApplication.getInstance(), android.R.layout.simple_dropdown_item_1line, data));
        autoCompeteView.setOnItemClickListener((parent, view, position, id) -> {
            bindingCommand.execute(data.get(position));
        });
    }
}
